import request from '@/utils/request'
import moment from 'moment'
// 本周
const startTime = moment(
  moment().week(moment().week()).startOf('week').valueOf()
).format('YYYY-MM-DD+HH:mm:ss')
const startTime1 = moment(
  moment().week(moment().week()).startOf('week').valueOf()
).format('YYYY-MM-DD')
const nowTime = moment(moment().valueOf()).format('YYYY-MM-DD')
const nowTime1 = moment(moment().valueOf()).format('YYYY-MM-DD+HH:mm:ss')
const nowMonth = moment(
  moment().month(moment().month()).startOf('month').valueOf()
).format('YYYY-MM-DD')
function randomstring (length) {
  const str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  let result = ''
  for (let i = length; i > 0; --i) {
    result += str[Math.floor(Math.random() * str.length)]
  }
  return result
}
// 本周
export const zhou =(userId)=>request.get(`/api/task-service/task/userWork?userId=${userId}&start=2022-11-28+00:00:00&end=2022-12-04+23:59:59`)
//本年
export const nian =(userId)=>request.get(`/api/task-service/task/userWork?userId=${userId}&start=2022-01-01+00:00:00&end=2022-12-04+23:59:59`)
//本月
export const yue =(userId)=>request.get(`/api/task-service/task/userWork?userId=${userId}&start=2022-12-01+00:00:00&end=2022-12-04+23:59:59`)

//获取用户基本信息
export const message=(id)=>request.get(`/api/user-service/user/${id}`)
// 获取用户工作量
export const userWork =(userId,start,end)=>request.get(`/api/task-service/task/userWork?userId=${userId}&start=${start}&end=${end}`)
// 获取图片验证码
export const imageCode = () => {
  return request.get('/api/user-service/user/imageCode/' + randomstring(8), {
    responseType: 'arraybuffer'
  })
}
// 登录接口
export const login = (data) =>
  request.post('/api/user-service/user/login', data)
// dashboard接口
// 1.1--合作商点位汇总统计
export const getCooperation = () => {
  return request.get(
    `/api/task-service/task/taskReportInfo/${nowMonth}%2000:00:00/${nowTime}%2023:59:59`
  )
}
// 1.2根据地区汇总销售额数据(销售量分布)
export const getarea = (id, start, end) => {
  return request.get(
    `/api/order-service/report/amountCollect/${id}/${start}/${end}`
  )
}
// 1.3获取10个故障设备列表
export const getfault = () => {
  return request.get('/api/status-service/status/top10')
}
// 1.4获取订单总数
export const getPartners = () => {
  return request.get(
    `/api/order-service/report/orderCount?start=${startTime}&end=${nowTime1}`
  )
}
// 1.5获取点位总数
export const getPoint = () => {
  return request.get('/api/vm-service/node/nodeCollect')
}
// 1.6获取销售前几的商品
export const getsale = () => {
  return request.get(
    `/api/order-service/report/skuTop/10/${startTime1}/${nowTime}`
  )
}
// 1.7获取销售额统计
export const getSales = () => {
  return request.get(
    `/api/order-service/report/orderAmount?start=${startTime}&end=${nowTime1}`
  )
}
// 1.7获取销售额分布
export const getAreas = (start, end) => {
  return request.get(`/api/order-service/report/regionCollect/${start}/${end}`)
}

// 工单搜索

export const workSearch = (data) => {
  return request.get('/api/task-service/task/search', {
    params: {
      ...data
    }
  })
}
// 人员列表搜索
export const userSearch =(data)=>request.get('/api/user-service/user/searchUserWork',{
  params:{
    ...data
  }
})
// 根据售货机获取运营人员列表
export const workPeopleList = (data) => {
  return request.get(`/api/user-service/user/operatorList/${data}`, {})
}
// 获取售货机货道详情
export const channelList = (id) => {
  return request.get(`/api/vm-service/channel/channelList/${id}`, {})
}
// 创建工单
export const newWork = (data) => {
  return request.post(
    '/api/task-service/task/create',
    data
  )
}
// 获取工单详情
export const taskInfo = taskId => request.get(`/api/task-service/task/taskInfo/${taskId}`)
// 获取补货警容线
export const supplyAlertValue = () => request.get('/api/task-service/task/supplyAlertValue')
// 上传补货警容线
export const autoSupplyConfig = (data) => request.post('/api/task-service/task/autoSupplyConfig', {
  alertValue: data
})
// 取消工单
export const cancelWorkA = (data) => {
  return request.post(
    `/api/task-service/task/cancel/${data.taskId}`,
    data
  )
}
// 获取工单列表
export const workList = (id = 1) => {
  return request.get(
    `/api/task-service/task/search?pageIndex=${id}&pageSize=10&isRepair=false`
  )
}
//补货详情
export const taskDetails=(taskId)=>request.get(`/api/task-service/taskDetails/${taskId}`)
//获取人员列表
export const userService=(id=1)=>request.get(`/api/user-service/user/searchUserWork?pageIndex=${id}&pageSize=10`)